﻿using System;
using System.Collections.Generic;
using System.Text;

namespace mvLibrary.Helpers.Enums
{
    public static class EnumUtils
    {
        [Serializable]
        [AttributeUsage(AttributeTargets.Field, Inherited = false)]
        public class DisplayValue : Attribute
        {
            public string DisplayString { get; private set; }

            public DisplayValue(string displayString)
            {
                this.DisplayString = displayString;
            }
        }

        public static IList<T> GetList<T>(T enumerable) where T :Type
        {
            IList<T> listaEnumerables = new List<T>();

            foreach (var elementoEnum in Enum.GetValues(enumerable))
            {
                listaEnumerables.Add((T)Enum.Parse(typeof(T), elementoEnum.ToString()));
            }

            return listaEnumerables;
        }

        //public static string GetDisplayName(Enum targetEnumValue)
        //{
        //    object displayInfoAttribute = targetEnumValue.GetType().GetField(targetEnumValue.ToString()).GetCustomAttributes(typeof(DisplayValue), false).FirstOrDefault();
        //    if (displayInfoAttribute != null)
        //    {
        //        return (displayInfoAttribute as DisplayValue).DisplayString;
        //    }
        //    return targetEnumValue.ToString();
        //}
    }
}
